package com.iss.airsys.dao;

import com.iss.airsys.entity.Guest;
import com.iss.airsys.model.GuestWithRoomfree;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GuestDao {
    @Insert("insert into guest values (null,#{guest_idcard},#{guest_name},#{guest_phone},#{guest_roomid},#{guest_checkintime},#{guest_checkouttime},#{guest_paymoney})")
    Integer insertGuest(Guest guest);
    @Select("select guest_id,guest_name,guest_idcard,guest_phone,room_id,guest_checkintime,guest_checkouttime,guest_paymoney from guest inner join roomfree on room_no=guest_roomid")
    List<GuestWithRoomfree> selectAllGuest();
    @Delete(" <script>"+"delete from guest where guest_id in" +
            "    <foreach collection=\"array\" item=\"guest_id\" separator=\",\" open=\"(\" close=\")\">" +
            "        #{guest_id}" +
            "    </foreach></script>")
    Integer deletGuest(Integer[] guest_id);
    @Update("update guest set guest_name=#{guest_name},guest_idcard=#{guest_idcard},guest_phone=#{guest_phone} where guest_id=#{guest_id}")
    Integer updateGuest(Guest guest);
    @Select("select * from guest where guest_id=#{guest_id}")
    Guest selectGuestById(Integer guest_id);
    @Update("update guest set guest_checkouttime=#{time} where guest_roomid=#{room_no}")
    Integer updateCheckoutTime(@Param("time") String time,@Param("room_no") Integer room_no);
}
